﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;

namespace Cherry.Agile.ServiceModel
{
    public class PaginationOperationBehaviorAttribute : Attribute, IOperationBehavior
    {


        public void AddBindingParameters(OperationDescription operationDescription, System.ServiceModel.Channels.BindingParameterCollection bindingParameters)
        {
           
        }

        public void ApplyClientBehavior(OperationDescription operationDescription
                , System.ServiceModel.Dispatcher.ClientOperation clientOperation)
        {
            
        }

        public void ApplyDispatchBehavior(OperationDescription operationDescription, System.ServiceModel.Dispatcher.DispatchOperation dispatchOperation)
        {
            
        }

        public void Validate(OperationDescription operationDescription)
        {
            
        }
    }

    public class PaginationParameterInspector : IParameterInspector
    {
        System.Threading.ThreadLocal<object[]> _inputs = new System.Threading.ThreadLocal<object[]>();
        //object[] _inputs;
        public void AfterCall(string operationName, object[] outputs, object returnValue, object correlationState)
        {
            if (_inputs.Value != null)
                PaginationProxyHandler.HandlerResults(_inputs.Value);
            _inputs.Value = null;
        }

        public object BeforeCall(string operationName, object[] inputs)
        {
            _inputs.Value = inputs;
            return null;
        }
    }

}

